package com.imooc.sm.service.impl;

import com.imooc.sm.dao.SelfDao;
import com.imooc.sm.dao.StaffDao;
import com.imooc.sm.entity.Staff;
import com.imooc.sm.service.SelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service("selfService")
public class SelfServiceImpl implements SelfService {
    @Autowired
    @Qualifier("selfDao")
    private SelfDao selfDao;
    @Autowired()
    @Qualifier("staffDao")
    private StaffDao staffDao;

    public Staff login(String sAccount, String sPassword) {
        Staff staff = selfDao.selectByAccount(sAccount);
        if (staff == null) {
            return null;
        }  //如果差不到该账号则返回空，结束
        if (staff.getPassword().equals(sPassword)) {
            return staff;
        }
        return null;//如果出现其他问题也返回空
    }

    /*修改密码*/
    public Staff changePassword(Integer sId, String sPassword) {
        Staff staff = staffDao.selectById(sId);
        staff.setPassword(sPassword);
        staffDao.update(staff);
        return staff;
    }
}
